package org.op.service.log;

import java.util.logging.FileHandler;
import java.util.logging.Level;
import java.util.logging.Logger;
import java.util.logging.SimpleFormatter;

public class LoggerServiceImpl implements LoggerService {

    private Logger logger;
    
    public static String LOGGER_LEVEL_SEVERE = Level.SEVERE.getName();
    public static String LOGGER_LEVEL_WARNING = Level.WARNING.getName();
    public static String LOGGER_LEVEL_INFO = Level.INFO.getName();
    
    private String defaultLogLevel;
    
    public LoggerServiceImpl() {
    }
    
	public void init(String filePath) throws Exception {
		logger = Logger.getLogger("org.op");
		FileHandler fh = new FileHandler(filePath);
		fh.setFormatter(new SimpleFormatter());
		logger.addHandler(fh);
	}
	
	public void log(String message) {
		log(message, defaultLogLevel);
	}

	public void log(String message, String level) {
		Level logLevel = Level.parse(level);
		logger.log(logLevel, message);		
	}

	public String getDefaultLogLevel() {
		return defaultLogLevel;
	}

	public void setDefaultLogLevel(String defaultLogLevel) {
		this.defaultLogLevel = defaultLogLevel;
	}

}
